<?php
namespace Frieza\Modules\Activity\Apis;

/**
 * User: @lose
 * Date: 2022/1/17
 * Time: 11:37 上午
 */

use App\Http\Controllers\Controller;
use Biz\model\activity\PageModule;
use Doraemon\model\Topic\TopicActivity;
use Doraemon\model\TopicTab;
use Doraemon\service\TopicTab as sTopicTab;
use Illuminate\Http\Request;

class Topiclist extends Controller
{
    public function index(Request $request)
    {
        $topics = TopicActivity::getAllTopic();
        $topicTabs = TopicTab::getAllTabs();
        $formatTopicTabs = [];
        foreach ($topicTabs as $topicTab) {
            $formatTopicTabs[$topicTab['topic_id']][] = $topicTab;
        }
        $formatTopicOptions = [];
        foreach ($topics as $topic) {
            $formatTopicOptions[$topic['id'] . PageModule::MODULE_WATERFALL_TAB_DELIMITER . sTopicTab::DEFAULT_TAB_HOT] = "[{$topic['id']}][热门-热度排序]{$topic['title']}";
            $formatTopicOptions[$topic['id'] . PageModule::MODULE_WATERFALL_TAB_DELIMITER . sTopicTab::DEFAULT_TAB_NEW] = "[{$topic['id']}][最新-时间排序]{$topic['title']}";
            if (isset($formatTopicTabs[$topic['id']])) {
                foreach ($formatTopicTabs[$topic['id']] as $tab) {
                    $formatTopicOptions[$topic['id'] . PageModule::MODULE_WATERFALL_TAB_DELIMITER . $tab['id']] = "[{$topic['id']}][{$tab['title']}-热度排序]{$topic['title']}";
                }
            }
        }
        return response()->json([
            'code' => 1,
            'data'  =>[
                'list' => $formatTopicOptions?: []
            ]
        ]);
    }
}